<template>
	<view class="u-p-30 page-view">
		<view class="order-view" @click="toDetail" v-if="order.serve_info">
			<view class="u-flex-1 u-font-30 font-medium w-0">
				<view class="u-line-1">{{order.serve_info.title || order.demand_info.title}}</view>
			</view>
			<view class="u-type-error">
				￥<text class="u-font-30">{{order.serve_info.price}}</text>
			</view>
		</view>
		<view class="u-border-bottom" v-for="(item,index) in replay" :key="index">
			<view class="u-flex">
				<view class="avatar">
					<u-avatar :src="item.avatar" size="80" :show-level="item.is_seller"
						:level-bg-color="config.mainColor"></u-avatar>
				</view>
				<text class="u-m-l-20 u-font-28 u-light-color">{{item.name || item.nickname}}</text>
				<view class="type-seller-tag" v-if="item.is_seller">
					卖家
				</view>
				<view class="type-buyyer-tag" v-else>
					买家
				</view>
				<view class="u-flex-1"></view>
				<view class="">
					<view class="evalate-item" v-if="item.type==1">
						<text class="iconfont icon-haoping"></text>好评
					</view>
					<view class="evalate-item" v-if="item.type==2">
						<text class="iconfont icon-average"></text>中评
					</view>
					<view class="evalate-item" v-if="item.type==3">
						<text class="iconfont icon-chaping"></text>差评
					</view>
				</view>
			</view>
			<view class="u-p-t-20 u-p-b-20 u-font-30">
				{{item.content}}
			</view>
			<view class="u-flex u-p-b-30 u-row-between">
				<text class="u-light-color u-font-22">{{item.add_time}}</text>
				<view class="u-type-primary u-font-22" @click="toEvaluate(index)" v-if="item.uid == userInfo.uid">修改评论</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				order: {},
				replay: [],
				userInfo: this.$store.state.vuex_userInfo,
				orderId: '',
				type: 1,
				role: '',
				config: this.$appConfig
			}
		},
		onLoad(e) {
			this.orderId = e.id
			this.type = e.type || 1;
			this.role = e.role

			if (this.type == 2) {
				this.queryDemOrder()
			} else {
				this.queryOrderDetail()
			}
		},
		onShow() {},
		methods: {
			queryOrderDetail() {
				this.$u.api.orderDetail(this.orderId).then(res => {
					this.order = res;
					this.replay = res.reply_list
				})
			},
			queryDemOrder() {
				console.log(this.role);
				if (this.role == 'power') {
					this.$u.api.demOrderInfo(this.orderId).then(res => {
						this.order = res;
						this.replay = res.reply_list
					})
				} else {
					this.$u.api.demOrderInfoByUser(this.orderId).then(res => {
						this.order = res;
						this.replay = res.reply_list
					})
				}

			},
			toEvaluate(index) {
				const {
					content,
					type
				} = this.replay[index];
				const contentJSON = JSON.stringify({
					content,
					type
				})
				this.$u.route('/pages/subpage/order/evaluate', {
					id: this.order.id,
					type: this.type,
					role: this.role,
					content: contentJSON
				})
			},
			toDetail() {
				if (this.type == 1) {
					this.$u.route('/pages/subpage/list/serv_detail', {
						id: this.order.serve_info.id
					})
				} else {
					this.$u.route('/pages/subpage/list/dem_detail', {
						id: this.order.demand_info.id
					})
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.page-view {
		height: 100vh;
		background-color: #ffffff;
	}

	.order-view {
		display: flex;
		padding: 28rpx;
		border-radius: 20rpx;
		background: #F6F6F6;
		margin-bottom: 30rpx;

		&:before {
			content: "";
			display: inline-block;
			width: 10rpx;
			height: 10rpx;
			border-radius: 50%;
			background-color: #999;
			margin-right: 16rpx;
			margin-top: 16rpx;
		}
	}

	.avatar {
		transform: scale(0.9);
	}

	.type-seller-tag {
		font-size: 16rpx;
		color: $u-type-primary;
		background-color: #E9FFF7;
		padding: 0 5rpx;
		border-radius: 6rpx;
		margin-left: 20rpx;
	}

	.type-buyyer-tag {
		font-size: 16rpx;
		color: $u-type-warning;
		background-color: #FFF2E2;
		padding: 0 5rpx;
		border-radius: 6rpx;
		margin-left: 20rpx;
	}

	.evalate-item {
		width: 78rpx;
		height: 31rpx;
		background: #F97B22;
		border-radius: 70rpx 70rpx 70rpx 70rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 16rpx;
		color: #ffffff;

		.iconfont {
			font-size: 20rpx;
			margin-right: 10rpx;
		}
	}
</style>